package filter.Demo;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class LoginServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //获取前端请求参数
        String uname = req.getParameter("uname");
        if (uname.equals("admin"))  //登录成功
        {
            req.getSession().setAttribute("USER_SESSION",req.getSession().getId());
            resp.sendRedirect("/8_Filter_war/sys/home.jsp");
        }else   //登录失败
        {
            resp.sendRedirect("/8_Filter_war/error.jsp");
        }

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
